Skip to content

Sync Sprint 1 exercises with the error-handling prep - #1460

Merged
Liam310 merged 2 commits into
mainfrom
error-handling-exercises
Sep 7, 2026
Merged

Sync Sprint 1 exercises with the error-handling prep#1460
Liam310 merged 2 commits into
mainfrom
error-handling-exercises

Conversation

@abdishakoor-dev

@abdishakoor-dev abdishakoor-dev commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

The Sprint 1 prep now covers throwing errors and try/catch, but the coursework still asked trainees to ignore non-numbers and return null. This brings the exercises in line with it.

The median, max and sum katas now expect a named error on bad input instead of a made-up value. Two new implement katas are added: mean, which throws when it can't calculate, and describe-median, which catches the error and returns a message.

Relevant Prep: https://curriculum.codeyourfuture.io/itp/data-groups/sprints/1/prep/#throwing-errors

Add mean and describe-median katas to implement, and change the existing
fix/implement exercises to throw on bad input instead of ignoring it,
matching the updated Sprint 1 prep.
@abdishakoor-dev abdishakoor-dev added the NotCoursework Not coursework - used for curriculum development work. label Sep 7, 2026
@CodeYourFuture CodeYourFuture deleted a comment from github-actions Bot Sep 7, 2026
@CodeYourFuture CodeYourFuture deleted a comment from github-actions Bot Sep 7, 2026
Comment thread Sprint-1/fix/median.test.js Outdated
Comment on lines +59 to +69
[1, 2, "3", null, undefined, 4],
["apple", 1, 2, 3, "banana", 4],
[1, "2", 3, "4", 5],
[1, "apple", 2, null, 3, undefined, 4],
[3, "apple", 1, null, 2, undefined, 4],
["banana", 5, 3, "apple", 1, 4, 2],
].forEach((input) =>
it(`throws for an array containing a non-number [${input}]`, () =>
expect(() => calculateMedian(input)).toThrow(
new Error("calculateMedian requires an array of numbers")
))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To throwback to a short conversation we had months ago, I'm not a fan of this setup for running tests for multiple reasons, namely:

  1. Difficult syntax for trainees who won't be familiar with forEach to parse
  2. Produces an output in the Jest CLI that is confusing

I recognise this is a problem for the happy path tests in this sprint as well. What do you think? Do you want to make changes here or should we put an issue in to refactor all tests to not use this structure?

Comment on lines +34 to +36
// Given an empty array
// When passed to describeMedian
// Then it should not throw

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that there is already a test described in comments above covering the behaviour of the function when given an empty array, what new behaviour is this test attempting to cover? The above tests check its return value, which I feel implicitly verifies it doesn't throw (if it did, there would be no return). What do you think?

Comment thread Sprint-1/implement/mean.test.js Outdated

In this kata, you will need to implement a function that calculates the mean of an array of numbers.

E.g. calculateMean([1, 2, 3]), target output: 2

@Liam310 Liam310 Sep 7, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: for this example input the mean is 2 but the median is also 2. Technically there isn't anything incorrect about this, but I could imagine people who are less mathematically confident to get mixed up by seeing the 2 in the middle of the array and thinking they understand what the "mean" is.

Perhaps calculateMean([1, 2, 6]), target output: 3 would avoid this risk?

Comment thread Sprint-1/implement/mean.test.js Outdated
// When passed to calculateMean
// Then it should return their mean
// Delete this test.todo and replace it with a test.
test.todo("given [1, 2, 3], returns 2");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same point as above comment!

@Liam310

Liam310 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

@abdishakoor-dev Looks good! I think this will be a really helpful addition to people and it follows on nicely from the prep (which is very clearly written).

Just a few small comments for your consideration 🙂

@abdishakoor-dev

Copy link
Copy Markdown
Contributor Author

median.test.js:
Agreed. I've split all the forEach blocks. This was the only file using them, so no need for an issue.

describe-median.test.js:
Agreed, it's redundant. Removed.

mean.test.js line 5:
Done, changed to [1, 2, 6] in the header and the test.todo.

mean.test.js line 26:
Done, see above.

@Liam310 Liam310 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@Liam310
Liam310 merged commit 4a13588 into main Sep 7, 2026
@Liam310
Liam310 deleted the error-handling-exercises branch September 7, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NotCoursework Not coursework - used for curriculum development work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants